import React, {
    Component,
} from 'react';
import {
    StyleSheet,
    Text,
    View,
    Platform,
    Dimensions,
    TouchableOpacity,
    Image,
    Alert,
    FlatList,
    TextInput,
    Linking,
    DeviceEventEmitter,
    ScrollView
} from 'react-native';

import moment from 'moment';
import HttpUtils from '../../utils/HttpUtils';
import HttpUrls from '../../utils/HttpUrls';
import AndroidModule from "../../utils/AndroidConnent";
import { ToastToUser } from "../../utils/CustomToast";
import Constant from '../../utils/Constant'
import NoData from '../../utils/NoData'
import Loading from "../../utils/Loading";
import { getImgUrl, getCarRegisterDate, getMileFormat, getPriceFormat } from '../../utils/ComFunction'
import BankInfoPop from '../offerprice/orderComponents/BankInfoPop';
import LinearGradient from 'react-native-linear-gradient';
import { conditionObjWithType } from '../../utils/Conditions'
import { OrderStatus, payType } from '../../utils/Enum'
import CancelOrderPop from './CancelOrderPop'
import Clipboard from '@react-native-clipboard/clipboard';
import CommonDialog from '../../components/dialog/CommonDialog';
import ConfirmPayPop from './ConfirmPayPop'
import CommonConfirmPop from '../../components/dialog/CommonConfirmPop';
import AlertCommonView from "../../components/Tool/AlertCommonView";

let navigation
/**
 * 普通收购/售出订单详情
 */
export default class NormalOrderDetail extends Component {
    constructor(props) {
        super(props);

        this.state = {
            title: '订单详情',
            orderNo: this.props.route.params.orderNo,
            carInfo: {},
            isShowBankInfo: false,
            orderStatus: 0,
            orderInfo: {},
            receivePaymentBank: '',
            receivePaymentBankAccount: '',
            receivePaymentAccountName: '',
            isShowCacelPop: false,

            checkStatus: '',//检测状态

            contractSignTimeOut: '',
            payTimeOut: '',
            shipmentTimeOut: '',
            receiptTimeOut: '',
            advanceConfirmTimeOut: '',
            advancePayTimeOut: '',
            tailConfirmTimeOut: '',
            tailPayTimeOut: '',
            logisticsTimeOut: '',//车辆运输中倒计时
            repetitionDetectionTimeOut: '',//复检倒计时
            settlinTimeOut: '',//结算倒计时

            logisticsInfo: {},//物流信息
            dialogVisible: false,

            afterSalesNo: '',
            buyerAfterSalesStatus: '',//1:买家提交申请，2：卖家同意，3：卖家拒绝，4：买家撤销
            certificateInfoRO: null,//过户资料
            detectionReportPic: '',
            detectionReportUrl: '',
            detectionReportPdf: '',
            transferDocumentUploaded: '',//0:未上传  1:已上传

            // 自提弹窗
            showAlertCommonView: false,
            showAlertData: {},

            paymentId: null, // 支付id
        }
    }

    componentDidMount() {

        this.uploadCheckReport = DeviceEventEmitter.addListener('uploadCheckReport', (result) => {
            console.log('uploadCheckReport', result)
            if (result) {
                this.setState({
                    detectionReportPic: result.detectionReportPic,
                    detectionReportUrl: result.detectionReportUrl,
                    detectionReportPdf: result.detectionReportPdf,
                }, function () {
                    this.orderUploadDetectionReport()
                })
            }
        })

        if (this.Loading) {
            this.Loading.show()
        }
        this.getOrderDetail()

        this.refreshOrderDetail = DeviceEventEmitter.addListener('refreshOrderDetail', (data) => {
            this.getOrderDetail()
        })
    }

    componentWillUnmount() {
        if (this.refreshOrderDetail) {
            this.refreshOrderDetail.remove()
        }
        if (this.uploadCheckReport) {
            this.uploadCheckReport.remove()
        }

    }

    render() {
        navigation = this.props.navigation;
        return (
            <View style={styles.container}>
                <Header navigation={navigation} Title={this.state.title} hideSepLine={true} bgColor={'#f9f9f9'} RightButton={() => this.renderRightButton()}></Header>

                <ScrollView
                    style={styles.scrollContain}
                    showsVerticalScrollIndicator={false}
                >
                    {this.renderOrderStatus()}
                    {this.renderAddressInfo()}
                    {this.renderOrderPayInfo()}
                    {this.renderDepositInfo()}
                    {this.renderOrderInfo()}

                    {/* {this.state.orderStatus == OrderStatus.OrderStatusWaitSettlement ? this.renderTailPayInfo() : null} */}

                    {/* {Constant.userInfo.isFranchisee == 0 && (this.state.orderStatus == OrderStatus.OrderStatusWaitPay
                        || this.state.orderStatus == OrderStatus.OrderStatusWaitSettlement) ?
                        <TouchableOpacity
                            style={styles.lookBankInfoContain}
                            onPress={() => {
                                this.setState({
                                    isShowBankInfo: true
                                })
                            }}>
                            <Text style={styles.lookBtnText}>{'查看收款账户 >'}</Text>
                        </TouchableOpacity>
                        :
                        <View style={[styles.lookBankInfoContain, { height: 10 }]}></View>
                    } */}

                </ScrollView>

                {this.renderBottom()}

                {this.state.isShowBankInfo ?
                    <BankInfoPop
                        navigation={navigation}
                        visible={this.state.isShowBankInfo}
                        onClose={() => {
                            this.setState({
                                isShowBankInfo: false
                            })
                        }}
                        receivePaymentBank={this.state.receivePaymentBank}
                        receivePaymentBankAccount={this.state.receivePaymentBankAccount}
                        receivePaymentAccountName={this.state.receivePaymentAccountName}

                    />
                    :
                    null
                }

                {this.state.isShowCacelPop ?
                    <CancelOrderPop
                        visible={this.state.isShowCacelPop}
                        onClose={() => {
                            this.setState({
                                isShowCacelPop: false
                            })
                        }}
                        onSure={(reason) => {
                            this.setState({
                                isShowCacelPop: false
                            })
                            this.cancelOrder(reason)
                            console.log('onSure')
                        }}
                        orderStatus={this.state.orderStatus}
                    >

                    </CancelOrderPop>
                    :
                    null
                }

                {this.state.dialogVisible ?
                    <CommonConfirmPop
                        visible={this.state.dialogVisible}
                        content={'请确认过户手续齐全并车辆状态正常，再支付尾款'}
                        onClose={() => {
                            this.setState({
                                dialogVisible: false
                            })
                        }}
                        onCancel={() => {
                            this.setState({
                                dialogVisible: false
                            })
                        }}
                        onSure={() => {
                            this.setState({
                                dialogVisible: false
                            })
                            navigation.navigate('UploadPayInfoPage', { orderNo: this.state.orderNo, from: '2', receiveId: this.state.orderInfo.sellerAccountId })
                        }}

                    >

                    </CommonConfirmPop>
                    :
                    null
                }

                {/* 弹窗提示 */}
                {
                    this.state.showAlertCommonView ?
                        <AlertCommonView
                            title={this.state.showAlertData.title}
                            content={this.state.showAlertData.content}
                            cancelBtnText={this.state.showAlertData.cancelBtnText}
                            sureBtnText={this.state.showAlertData.sureBtnText}
                            cancelHandler={() => {
                                this.setState({
                                    showAlertCommonView: false
                                })
                            }}
                            sureHandler={() => {
                                this.setState({
                                    showAlertCommonView: false
                                })
                                if (this.state.showAlertData.type === 'ziti') {
                                    // this.consultOnline()
                                    this.ziTi()
                                }else if (this.state.showAlertData.type === 'payConfirm') {
                                    this.checkPayStatus()
                                }
                            }}
                        />
                        :
                        null
                }

                <Loading onRef={(ref) => (this.Loading = ref)} />

            </View>
        )
    }

    renderRightButton() {

        if(
            this.state.orderInfo
            && Constant.userInfo.userId == this.state.orderInfo.buyerUserId
            && Constant.userInfo.isFranchisee == '0'
            && this.state.orderStatus == OrderStatus.OrderStatusWaitDelivery
            && this.state.orderInfo.isSelfPickup == '0'
            && ((!this.state.orderInfo.deliveryConfirm || this.state.orderInfo.deliveryConfirm == '0') && (!this.state.orderInfo.shippingConfirm || this.state.orderInfo.shippingConfirm == '0'))
        ){
            return (
                <TouchableOpacity
                    activeOpacity={0.8}
                    onPress={() => {
                        const advancePaymentRate = this.state.orderInfo.advancePaymentRate
                        let title = `请确认是否提车，确认后将预付${advancePaymentRate}%车款?`
                        // 弹窗确认
                        this.setState({
                            showAlertData: {
                                title: title,
                                cancelBtnText: '取消',
                                sureBtnText: '确定',
                                type: 'ziti'
                            },
                            showAlertCommonView: true,
                        })
                    }}>
                    <View style={styles.rightBox}>
                        <Text style={styles.rightText}>我已自提</Text>
                    </View>
                </TouchableOpacity>
            )
        }


        if (
            this.state.orderInfo
            && (this.state.orderInfo.logisticsStatus == '30' || this.state.orderInfo.isSelfPickup == '1')
            && this.state.orderStatus == OrderStatus.OrderStatusWaitReceipt
            && Constant.userInfo.isFranchisee == '0'
        ) {
            return (
                <TouchableOpacity
                    activeOpacity={0.8}
                    onPress={() => {
                        let params = {
                            detectionReportPic: '',
                            detectionReportUrl: '',
                            detectionReportPdf: ''
                        }
                        AndroidModule.selectCarDetection(params, (error, result) => {
                            this.setState({
                                detectionReportPic: result.detectionReportPic,
                                detectionReportUrl: result.detectionReportUrl,
                                detectionReportPdf: result.detectionReportPdf
                            }, function () {
                                this.orderUploadDetectionReport()
                            })
                            console.log('result', result)
                        })
                    }}>
                    <View style={styles.rightBox}>
                        <Text style={styles.rightText}>上传报告</Text>
                    </View>
                </TouchableOpacity>
            )
        } else {
            return null
        }

    }

    renderOrderStatus() {
        return (
            <View style={styles.orderStatusContain}>
                <Text style={styles.orderStatusText}>{this.getOrderStatusTitleText()}</Text>
                {this.getOrderStatusText()}

            </View>
        )
    }

    getOrderStatusTitleText() {

        if (this.state.orderStatus != OrderStatus.OrderStatusCanceled && this.state.orderStatus != OrderStatus.OrderStatusFinisded &&
            this.state.orderStatus != OrderStatus.OrderStatusClosed) {
            if (Constant.userInfo.isFranchisee == '1') {
                if (this.state.orderInfo.sellerCancelStatus == '1') {//卖家发起
                    return '已申请取消订单，待确认'
                }
                if (this.state.orderInfo.buyerCancelStatus == '1') {//买家发起
                    return '收到订单取消，请确认'
                }
            } else {
                if (this.state.orderInfo.buyerCancelStatus == '1') {
                    return '已申请取消订单，待确认'
                }
                if (this.state.orderInfo.sellerCancelStatus == '1') {
                    return '收到订单取消，请确认'
                }
            }
        }



        if (this.state.checkStatus == '' || this.state.checkStatus == '1') {//未提交检测
            if (this.state.orderStatus == OrderStatus.OrderStatusCanceled) {
                return '订单已取消'
            }
            return '车辆待检测'
        } else if (this.state.checkStatus == '2') {//检测中
            return '等待车辆检测结果'
        } else if (this.state.checkStatus == '3') {//检测完成
            if (this.state.orderStatus == OrderStatus.OrderStatusWaitSign) {
                if (Constant.userInfo.isFranchisee == '1') {//卖家
                    return '待签署合同'
                } else {//买家
                    return '请签署合同'
                }

            } else if (this.state.orderStatus == OrderStatus.OrderStatusSigning) {

                if (Constant.userInfo.isFranchisee == '1') {//卖家

                    if (this.isSellerNotContractSign()) {//卖家未签署
                        return '请签署合同'
                    } else {
                        if (this.isBuyerNotContractSign()) {//买家未签署
                            return '待签署合同'
                        }
                    }
                } else {

                    if (this.isBuyerNotContractSign()) {//买家未签署
                        return '请签署合同'
                    } else {
                        if (this.isSellerNotContractSign()) {//卖家未签署
                            return '待签署合同'
                        }
                    }
                }

            } else if (this.state.orderStatus == OrderStatus.OrderStatusRejectSign) {
                return '合同已拒签'
            }
            else if (this.state.orderStatus == OrderStatus.OrderStatusWaitDelivery) {
                if (Constant.userInfo.isFranchisee == '1') {//卖家
                    if (this.state.orderInfo.shippingConfirm == '1') {//已确认
                        if (this.state.orderInfo.deliveryConfirm == '1') {
                            if (this.state.logisticsInfo && this.state.logisticsInfo.transportStatus == '2') {
                                return '司机已提车，待发货'
                            }
                            return '物流已下单，待司机提车'
                        }
                        return '待确认物流信息'
                    } else {

                        return '请确认物流信息'
                    }
                } else {
                    if (this.state.orderInfo.deliveryConfirm == '1') {//收货方已确认
                        if (this.state.orderInfo.shippingConfirm == '1') {
                            if (this.state.logisticsInfo && this.state.logisticsInfo.transportStatus == '2') {
                                return '司机已提车，待发货'
                            }
                            return '物流已下单，待司机提车'
                        }
                        return '待确认物流信息'
                    } else {
                        return '请确认物流信息'

                    }
                }

            }
            else if (this.state.orderStatus == OrderStatus.OrderStatusWaitPay) {//待付款

                if (Constant.userInfo.isFranchisee == '1') {
                    return '待收款'
                } else {
                    return '请付款'
                }


            }
            else if (this.state.orderStatus == OrderStatus.OrderStatusWaitReceipt) {
                if (Constant.userInfo.isFranchisee == '1') {//卖家

                    if (this.state.logisticsInfo && this.state.logisticsInfo.transportStatus == '2') {
                        return '司机已提车，待发货'
                    } else if (this.state.orderInfo.logisticsStatus == '30') {//已确认
                        return '物流已交车，待复检'
                    } else if(this.state.orderInfo.isSelfPickup == '1'){
                        return '已自提，待复检'
                    } else {
                        return '车辆运输中'
                    }
                } else {
                    if (this.state.logisticsInfo && this.state.logisticsInfo.transportStatus == '2') {
                        return '司机已提车，待发货'
                    } else if (this.state.orderInfo.logisticsStatus == '30') {//已确认
                        return '物流已交车，请复检'
                    } else if (this.state.orderInfo.isSelfPickup == '1') {
                        return '已自提，请复检'
                    } else {
                        return '车辆运输中'
                    }

                }

            } else if (this.state.orderStatus == OrderStatus.OrderStatusWaitSettlement) {

                if (Constant.userInfo.isFranchisee == '1') {//卖家

                    return '待确认收货'
                } else {

                    return '请确认收货'
                }

            } else if (this.state.orderStatus == OrderStatus.OrderStatusServicing) {
                return '售后中'
            } else if (this.state.orderStatus == OrderStatus.OrderStatusFinisded) {//交易完成

                if (Constant.userInfo.isFranchisee == '1') {//卖家
                    return '交易完成'
                } else {
                    if (this.state.transferDocumentUploaded == '1') {
                        return '交易完成'
                    } else {
                        return '请提交过户资料'
                    }
                }



            } else if (this.state.orderStatus == OrderStatus.OrderStatusCanceled) {
                return '订单已取消'
            } else if (this.state.orderStatus == OrderStatus.OrderStatusClosed) {
                return '订单已关闭'
            }
        }
    }

    isBuyerNotContractSign() {
        return !this.state.orderInfo.buyerContractSign || this.state.orderInfo.buyerContractSign == '0'
    }

    isSellerNotContractSign() {
        return !this.state.orderInfo.sellerContractSign || this.state.orderInfo.sellerContractSign == '0'
    }

    getOrderStatusText() {

        if (this.state.orderStatus != OrderStatus.OrderStatusCanceled && this.state.orderStatus != OrderStatus.OrderStatusFinisded
            && this.state.orderStatus != OrderStatus.OrderStatusClosed) {
            if (Constant.userInfo.isFranchisee == '1') {
                if (this.state.orderInfo.sellerCancelStatus == '1' || this.state.orderInfo.buyerCancelStatus == '1') {//卖家发起
                    if (this.state.orderStatus == OrderStatus.OrderStatusWaitSign || this.state.orderStatus == OrderStatus.OrderStatusSigning) {
                        return (
                            <Text style={styles.orderStatusText2}>若双方同意，将无责取消</Text>
                        )
                    } else {
                        if (this.state.orderInfo.buyerCancelStatus == '1') {
                            return (
                                <Text style={styles.orderStatusText2}>违约取消，将收到<Text style={{ color: '#ED542E' }}>2000</Text>保证金补偿</Text>
                            )
                        } else {
                            return (
                                <Text style={styles.orderStatusText2}>违约取消，将扣除<Text style={{ color: '#ED542E' }}>2000</Text>保证金补偿对方</Text>
                            )
                        }

                    }


                }

            } else {
                if (this.state.orderInfo.buyerCancelStatus == '1' || this.state.orderInfo.sellerCancelStatus == '1') {
                    if (this.state.orderStatus == OrderStatus.OrderStatusWaitSign || this.state.orderStatus == OrderStatus.OrderStatusSigning) {
                        return (
                            <Text style={styles.orderStatusText2}>若双方同意，将无责取消</Text>
                        )
                    } else {
                        if (this.state.orderInfo.buyerCancelStatus == '1') {
                            return (
                                <Text style={styles.orderStatusText2}>违约取消，将扣除<Text style={{ color: '#ED542E' }}>2000</Text>保证金补偿对方</Text>
                            )
                        } else {
                            return (
                                <Text style={styles.orderStatusText2}>违约取消，将收到<Text style={{ color: '#ED542E' }}>2000</Text>保证金补偿</Text>
                            )
                        }

                    }
                }

            }
        }


        if (this.state.checkStatus != '3') {
            return null
        }

        if (this.state.orderStatus == OrderStatus.OrderStatusWaitSign || this.state.orderStatus == OrderStatus.OrderStatusSigning) {
            if (this.state.contractSignTimeOut === 0) {
                return (
                    <Text style={styles.orderStatusText2}>已超时</Text>
                )
            }
            if (Constant.userInfo.isFranchisee == '1') {
                // if ((this.isBuyerNotContractSign() && this.isSellerNotContractSign())
                //     || (this.state.orderInfo.buyerContractSign == '1' && this.isSellerNotContractSign())) {//均未签署  买家已签署，卖家未签署
                //     if (this.state.contractSignTimeOut == 0) {
                //         return (
                //             <Text style={styles.orderStatusText2}>已超时</Text>
                //         )
                //     }
                //     return (
                //         <Text style={styles.orderStatusText2}>请及时签署，<Text style={styles.timeColorText}>{this.formatTime(this.state.contractSignTimeOut)}</Text>后平台将介入</Text>
                //     )
                // } else if (this.isBuyerNotContractSign() && this.state.orderInfo.sellerContractSign == '1') {//卖家已签署，买家未签署
                //     return null
                // } else {
                //     return null
                // }


                if (this.isSellerNotContractSign()) {//卖家未签署
                    return (
                        <Text style={styles.orderStatusText2}>请及时签署，<Text style={styles.timeColorText}>{this.formatTime(this.state.contractSignTimeOut)}</Text>后平台将介入</Text>
                    )
                } else {
                    if (this.isBuyerNotContractSign()) {//买家未签署
                        return (
                            <Text style={styles.orderStatusText2}>对方若<Text style={styles.timeColorText}>{this.formatTime(this.state.contractSignTimeOut)}</Text>后未签署，平台将介入</Text>
                        )
                    }
                }
            } else {
                // if ((this.isBuyerNotContractSign() && this.isSellerNotContractSign())
                //     || (this.isBuyerNotContractSign() && this.state.orderInfo.sellerContractSign == '1')) {//均未签署
                //     if (this.state.contractSignTimeOut == 0) {
                //         return (
                //             <Text style={styles.orderStatusText2}>已超时</Text>
                //         )
                //     }
                //     return (
                //         <Text style={styles.orderStatusText2}>请及时签署，<Text style={styles.timeColorText}>{this.formatTime(this.state.contractSignTimeOut)}</Text>后将平台介入</Text>
                //     )
                // } else if (this.state.orderInfo.buyerContractSign == '1' && this.isSellerNotContractSign()) {//买家已签署，卖家未签署
                //     return null
                // } else {
                //     return null
                // }

                if (this.isBuyerNotContractSign()) {//未签署
                    return (
                        <Text style={styles.orderStatusText2}>请及时签署，<Text style={styles.timeColorText}>{this.formatTime(this.state.contractSignTimeOut)}</Text>后平台将介入</Text>
                    )
                } else {
                    if (this.isSellerNotContractSign()) {//未签署
                        return (
                            <Text style={styles.orderStatusText2}>对方若<Text style={styles.timeColorText}>{this.formatTime(this.state.contractSignTimeOut)}</Text>后未签署，平台将介入</Text>
                        )
                    }
                }
            }

        } else if (this.state.orderStatus == OrderStatus.OrderStatusWaitDelivery) {
            if (this.state.shipmentTimeOut === 0) {
                return (
                    <Text style={styles.orderStatusText2}>已超时</Text>
                )
            }
            if (Constant.userInfo.isFranchisee == '1') {//卖家
                if (this.state.orderInfo.shippingConfirm == '1') {//已确认
                    return (
                        <Text style={styles.orderStatusText2}><Text style={styles.timeColorText}>{this.formatTime(this.state.shipmentTimeOut)}</Text>后平台将介入</Text>
                    )
                } else {
                    return (
                        <Text style={styles.orderStatusText2}>请及时确认，<Text style={styles.timeColorText}>{this.formatTime(this.state.shipmentTimeOut)}</Text>后平台将介入</Text>
                    )
                }
            } else {
                if (this.state.orderInfo.deliveryConfirm == '1') {//已确认
                    return (
                        <Text style={styles.orderStatusText2}><Text style={styles.timeColorText}>{this.formatTime(this.state.shipmentTimeOut)}</Text>后平台将介入</Text>
                    )
                } else {
                    return (
                        <Text style={styles.orderStatusText2}>请及时确认，<Text style={styles.timeColorText}>{this.formatTime(this.state.shipmentTimeOut)}</Text>后平台将介入</Text>
                    )
                }
            }

        } else if (this.state.orderStatus == OrderStatus.OrderStatusWaitPay) {//待付款
            if (this.state.payTimeOut === 0) {
                return (
                    <Text style={styles.orderStatusText2}>已超时</Text>
                )
            }
            if (Constant.userInfo.isFranchisee == '1') {//卖家

                return (
                    <Text style={styles.orderStatusText2}><Text style={styles.timeColorText}>{this.formatTime(this.state.payTimeOut)}</Text>后未支付，平台将介入</Text>
                )
            } else {

                return (
                    <Text style={styles.orderStatusText2}>请及时确认支付，<Text style={styles.timeColorText}>{this.formatTime(this.state.payTimeOut)}</Text>后平台将介入</Text>
                )
            }
        }
        else if (this.state.orderStatus == OrderStatus.OrderStatusWaitReceipt) {

            if (Constant.userInfo.isFranchisee == '1') {//卖家

                if(this.state.orderInfo.isSelfPickup == '1'){ // 物流自提
                    return (
                        <Text style={styles.orderStatusText2}><Text style={styles.timeColorText}>{this.formatTime(this.state.repetitionDetectionTimeOut)}</Text>后未交车平台将介入</Text>
                    )
                }

                if (this.state.orderInfo.logisticsStatus == '30') {
                    if (this.state.repetitionDetectionTimeOut === 0) {
                        return (
                            <Text style={styles.orderStatusText2}>已超时</Text>
                        )
                    }
                    return (
                        <Text style={styles.orderStatusText2}><Text style={styles.timeColorText}>{this.formatTime(this.state.repetitionDetectionTimeOut)}</Text>后未出复检平台将介入</Text>
                    )
                } else {
                    if (this.state.logisticsTimeOut === 0) {
                        return (
                            <Text style={styles.orderStatusText2}>已超时</Text>
                        )
                    }
                    return (
                        <Text style={styles.orderStatusText2}>物流跟进中，<Text style={styles.timeColorText}>{this.formatTime(this.state.logisticsTimeOut)}</Text>后未交车平台将介入</Text>
                    )
                }
            } else {

                if(this.state.orderInfo.isSelfPickup == '1'){ // 物流自提
                    return (
                        <Text style={styles.orderStatusText2}><Text style={styles.timeColorText}>{this.formatTime(this.state.repetitionDetectionTimeOut)}</Text>后未交车平台将介入</Text>
                    )
                }

                if (this.state.orderInfo.logisticsStatus == '30') {
                    if (this.state.repetitionDetectionTimeOut === 0) {
                        return (
                            <Text style={styles.orderStatusText2}>已超时</Text>
                        )
                    }
                    return (
                        <Text style={styles.orderStatusText2}><Text style={styles.timeColorText}>{this.formatTime(this.state.repetitionDetectionTimeOut)}</Text>后未出复检，平台将介入</Text>
                    )
                } else {
                    if (this.state.logisticsTimeOut === 0) {
                        return (
                            <Text style={styles.orderStatusText2}>已超时</Text>
                        )
                    }
                    return (
                        <Text style={styles.orderStatusText2}>物流跟进中，<Text style={styles.timeColorText}>{this.formatTime(this.state.logisticsTimeOut)}</Text>后未交车平台将介入</Text>
                    )
                }
            }

        } else if (this.state.orderStatus == OrderStatus.OrderStatusWaitSettlement) {
            if (Constant.userInfo.isFranchisee == '1') {//卖家
                if (this.state.settlinTimeOut === 0) {
                    return (
                        <Text style={styles.orderStatusText2}>已超时</Text>
                    )
                }
                return (
                    <Text style={styles.orderStatusText2}><Text style={styles.timeColorText}>{this.formatTime(this.state.settlinTimeOut)}</Text>后未确认，平台将介入</Text>
                )
            } else {
                if (this.state.settlinTimeOut === 0) {
                    return (
                        <Text style={styles.orderStatusText2}>已超时</Text>
                    )
                }
                return (
                    <Text style={styles.orderStatusText2}>请在过户后确认，<Text style={styles.timeColorText}>{this.formatTime(this.state.settlinTimeOut)}</Text>后平台将介入</Text>
                )
            }

        } else if (this.state.orderStatus == OrderStatus.OrderStatusServicing) {

        } else if (this.state.orderStatus == OrderStatus.OrderStatusFinisded) {

        } else if (this.state.orderStatus == OrderStatus.OrderStatusCanceled) {

        }
    }

    formatTime(seconds) {
        if (seconds == null || seconds == undefined) {
            return '';
        }
        const h = Math.floor(seconds / 3600);
        const m = Math.floor((seconds % 3600) / 60);
        const s = seconds % 60;

        // const formattedH = h.toString().padStart(2, '0');
        // const formattedM = m.toString().padStart(2, '0');
        // const formattedS = s.toString().padStart(2, '0');

        if (h == 0) {
            return ` ${m}分${s}秒`;
        }
        return ` ${h}小时${m}分${s}秒`;
    }

    renderAddressInfo() {
        return (
            <View style={styles.addressInfoBox}
            >
                <Image style={styles.locationImg} source={require('source/image/location_icon.png')} />
                {
                    JSON.stringify(this.state.orderInfo) !== '{}' ?
                        <View style={{ flex: 1, flexDirection: 'column', alignItems: 'flex-start', justifyContent: 'center', marginLeft: 12 }}>
                            <Text style={styles.addressText} numberOfLines={1} ellipsizeMode={'tail'}>{this.state.orderInfo.buyerAddressStr}</Text>
                            <Text style={styles.nameText}>{this.state.orderInfo.buyerConsigneeName + ' ' + this.state.orderInfo.buyerConsigneePhone}</Text>
                        </View>
                        :
                        null
                }


            </View>
        )
    }

    getSendRecvUserInfo() {
        if (Constant.userInfo.isFranchisee == 1) {
            return this.state.orderInfo.buyerUserName
        } else {
            return this.state.orderInfo.sellerUserName
        }
    }

    renderOrderPayInfo() {
        return (
            <View style={styles.orderInfoContain}>
                <Text style={styles.titleText}>{Constant.userInfo.isFranchisee == 1 ? this.state.orderInfo.buyerMerchantAbbreviation : this.state.orderInfo.sellerMerchantAbbreviation}</Text>
                <TouchableOpacity style={{ flexDirection: 'row', alignItems: 'center' }}
                                  onPress={() => { navigation.navigate('CarDetailPage', { carId: this.state.orderInfo.carId, merchantId: this.state.orderInfo.sellerMerchantId }) }}>
                    <Image style={styles.carImg} source={{ uri: getImgUrl(this.state.orderInfo.mainPic) }} />
                    <View style={styles.carInfoBox}>
                        <Text style={styles.brandText}>{this.state.orderInfo.carName ? this.state.orderInfo.carName.replaceAll('#', ' ') : ''}</Text>
                        <Text style={styles.carInfoText}>{this.getSubCarInfo(this.state.orderInfo)}</Text>
                        <Text style={styles.carPriceText}>{'成交价 ' + (this.state.orderInfo.quotationAmount / (100 * 10000))}万元</Text>
                    </View>
                </TouchableOpacity>

                {(this.state.orderInfo.logisticsNo && this.state.orderInfo.logisticsNo != '') ||
                (this.state.orderInfo.contractNo && this.state.orderInfo.contractNo != '') ?
                    <View style={styles.carbottomContain}>
                        {this.state.orderInfo.logisticsNo && this.state.orderInfo.logisticsNo != '' ?
                            <TouchableOpacity
                                style={styles.carBottomBtn}
                                activeOpacity={0.8}
                                onPress={() => {
                                    navigation.navigate('LogisticsTrackPage', { logisticsNo: this.state.orderInfo.logisticsNo });
                                }}>
                                <Text style={styles.carBottomBtnText}>查看物流</Text>
                            </TouchableOpacity>

                            : null
                        }


                        {this.state.orderInfo.contractNo && this.state.orderInfo.contractNo != '' ?
                            <TouchableOpacity
                                style={styles.carBottomBtn}
                                activeOpacity={0.8}
                                onPress={() => {
                                    navigation.navigate('ContractDetailPage', { contractNo: this.state.orderInfo.contractNo, orderNo: this.state.orderNo });
                                }}>
                                <Text style={styles.carBottomBtnText}>查看合同</Text>
                            </TouchableOpacity>
                            : null
                        }


                    </View>
                    : null

                }

                <View style={styles.itemPriceContain}>
                    <Text style={styles.itemPriceTitle}>预付比例</Text>
                    <Text style={styles.itemPriceValue}>{this.state.orderInfo.advancePaymentRate}%</Text>
                </View>

                <View style={styles.itemPriceContain}>
                    <Text style={styles.itemPriceTitle}>预付车款</Text>
                    <Text style={styles.itemPriceValue}>¥{this.state.orderInfo.advancePayment / (100)}</Text>
                </View>

                <View style={styles.itemPriceContain}>
                    <Text style={styles.itemPriceTitle}>预结算尾款</Text>
                    <Text style={styles.itemPriceValue}>¥{this.state.orderInfo.tailPayment / (100)}</Text>
                </View>

                <View style={styles.itemPriceContain}>
                    <Text style={styles.itemPriceTitle}>门店服务费</Text>
                    <Text style={styles.itemPriceValue}>¥{this.state.orderInfo.detectionFee / (100)}</Text>
                </View>

                <View style={styles.itemPriceContain}>
                    <Text style={styles.itemPriceTitle}>运费</Text>
                    <Text style={styles.itemPriceValue}>到付</Text>
                </View>
                <View style={styles.itemPriceContain}>
                    <Text style={styles.itemPriceTitle}>总计</Text>
                    <Text style={[styles.itemPriceValue, { color: '#ED542E' }]}>¥{this.state.orderInfo.tradePrice / (100)}</Text>
                </View>

            </View>
        )
    }

    getSubCarInfo(item) {

        let carInfoStr = ''
        if (item.registerDate && item.registerDate != null) {


            carInfoStr = moment(item.registerDate).format('YYYY-MM')
        }

        if (item.mileage && item.mileage != 0) {
            carInfoStr = carInfoStr + ' | ' + getMileFormat(item.mileage)
        }

        if (item.sellerUserCityName && item.sellerUserCityName != '') {
            if (carInfoStr != '') {
                carInfoStr = carInfoStr + ' | ' + item.sellerUserCityName
            } else {
                carInfoStr = item.sellerUserCityName
            }

        }

        return carInfoStr
    }

    renderDepositInfo() {
        return (
            <View style={styles.orderInfoContain}>
                <View style={styles.infoBox}>
                    <Text style={styles.itemTitleText}>保证金</Text>
                    <Text style={styles.itemTitleText}>{'从保证金账户冻结，交易完成后解冻'}</Text>
                </View>
                <View style={styles.infoBox}>
                    <Text style={styles.itemTitleText}>信用担保</Text>
                    <Text style={styles.itemPriceText}>¥{this.state.orderInfo.contractDeposit / 100}</Text>
                </View>
                {Constant.userInfo.isFranchisee == 1 ?
                    <View style={styles.infoBox}>
                        <Text style={styles.itemTitleText}>价值担保</Text>
                        <Text style={styles.itemPriceText}>¥{this.state.orderInfo.carDeposit / 100}</Text>
                    </View>
                    :
                    null
                }


            </View>
        )
    }

    renderOrderInfo() {
        return (
            <View style={styles.orderInfoContain}>
                <View style={styles.infoBox}>
                    <Text style={styles.itemTitleText}>订单编号</Text>
                    <View style={{ flexDirection: 'row', alignItems: 'center' }}>
                        <Text style={styles.itemTitleText}>{this.state.orderNo}</Text>
                        <TouchableOpacity
                            style={{ width: 30, height: 30, justifyContent: 'center', alignItems: 'center' }}
                            onPress={() => { this.copyText(this.state.orderNo) }}>
                            <Image style={styles.copyImg} source={require('source/image/comm/icon_copy.png')} />
                        </TouchableOpacity>
                    </View>

                </View>

                {/**
                 * 取消申请页面和取消完成页面显示，取消失败回到原流程时不显示
                 */}
                {this.state.orderInfo.cancelReason && this.state.orderInfo.cancelReason != ''
                && (this.state.orderInfo.buyerCancelStatus == '1' || this.state.orderInfo.sellerCancelStatus == '1'
                    || this.state.orderStatus == OrderStatus.OrderStatusCanceled) ?
                    <View style={styles.infoBox}>
                        <Text style={styles.itemTitleText}>取消理由</Text>
                        <Text style={styles.itemTitleText}>{this.state.orderInfo.cancelReason}</Text>
                    </View>
                    :
                    null
                }


                <View style={styles.infoBox}>
                    <Text style={styles.itemTitleText}>创建时间</Text>
                    <Text style={styles.itemTitleText}>{this.state.orderInfo.createTime}</Text>
                </View>
                {this.state.orderInfo.contractSignCompleteTime && this.state.orderInfo.contractSignCompleteTime != '' ?
                    <View style={styles.infoBox}>
                        <Text style={styles.itemTitleText}>合同签署时间</Text>
                        <Text style={styles.itemTitleText}>{moment(this.state.orderInfo.contractSignCompleteTime).format('YYYY-MM-DD HH:mm:ss')}</Text>
                    </View>
                    :
                    null
                }

                {/* {this.state.orderStatus != OrderStatus.OrderStatusWaitSign && this.state.orderStatus != OrderStatus.OrderStatusSigning ?
                    <View style={styles.infoBox}>
                        <Text style={styles.itemTitleText}>收货地址</Text>
                        <Text style={styles.itemTitleText}>{this.state.createTime}</Text>
                    </View>
                    :
                    null
                } */}

                {this.state.orderInfo.paymentTime && this.state.orderInfo.paymentTime != '' ?
                    <View style={styles.infoBox}>
                        <Text style={styles.itemTitleText}>付款时间</Text>
                        <Text style={styles.itemTitleText}>{moment(this.state.orderInfo.paymentTime).format('YYYY-MM-DD HH:mm:ss')}</Text>
                    </View>
                    :
                    null
                }

                {this.state.orderInfo.shipperTime && this.state.orderInfo.shipperTime != '' ?
                    <View style={styles.infoBox}>
                        <Text style={styles.itemTitleText}>发货时间</Text>
                        <Text style={styles.itemTitleText}>{moment(this.state.orderInfo.shipperTime).format('YYYY-MM-DD HH:mm:ss')}</Text>
                    </View>
                    :
                    null
                }



                {/* {this.state.orderInfo.advancePaymentTime && this.state.orderInfo.advancePaymentTime != '' ?
                    <View style={styles.infoBox}>
                        <Text style={styles.itemTitleText}>支付预付款时间</Text>
                        <Text style={styles.itemTitleText}>{moment(this.state.orderInfo.advancePaymentTime).format('YYYY-MM-DD HH:mm:ss')}</Text>
                    </View>
                    :
                    null
                } */}

                {/* {this.state.orderStatus != OrderStatus.OrderStatusWaitSign && this.state.orderStatus != OrderStatus.OrderStatusSigning
                    && this.state.orderStatus != OrderStatus.OrderStatusWaitDelivery ?
                    <View style={styles.infoBox}>
                        <Text style={styles.itemTitleText}>支付方式</Text>
                        <Text style={styles.itemTitleText}>{this.state.createTime}</Text>
                    </View>
                    :
                    null
                } */}

                {/* {this.state.orderInfo.tailPaymentTime && this.state.orderInfo.tailPaymentTime != '' ?
                    <View style={styles.infoBox}>
                        <Text style={styles.itemTitleText}>支付尾款时间</Text>
                        <Text style={styles.itemTitleText}>{moment(this.state.orderInfo.tailPaymentTime).format('YYYY-MM-DD HH:mm:ss')}</Text>
                    </View>
                    :
                    null
                } */}

                {this.state.orderInfo.transactionCompleteTime && this.state.orderInfo.transactionCompleteTime != '' ?
                    <View style={styles.infoBox}>
                        <Text style={styles.itemTitleText}>交易完成时间</Text>
                        <Text style={styles.itemTitleText}>{moment(this.state.orderInfo.transactionCompleteTime).format('YYYY-MM-DD HH:mm:ss')}</Text>
                    </View>
                    :
                    null
                }

                {this.state.orderInfo.cancelTime && this.state.orderInfo.cancelTime != '' ?
                    <View style={styles.infoBox}>
                        <Text style={styles.itemTitleText}>订单关闭时间</Text>
                        <Text style={styles.itemTitleText}>{moment(this.state.orderInfo.cancelTime).format('YYYY-MM-DD HH:mm:ss')}</Text>
                    </View>
                    :
                    null
                }


            </View>
        )
    }

    renderTailPayInfo() {
        return (
            <View style={styles.orderInfoContain}>
                <View style={styles.infoBox}>
                    <Text style={styles.itemTitleText}>尾款支付</Text>
                    <Text style={styles.payPriceText}>¥{this.state.orderInfo.tailPayment / 100}</Text>
                </View>


                <View style={styles.infoBox}>
                    <Text style={styles.itemTitleText}>门店服务费</Text>
                    <Text style={styles.payPriceText}>¥{this.state.orderInfo.detectionFee / 100}</Text>
                </View>

                <View style={styles.infoBox}>
                    <Text style={styles.itemTitleText}>总计</Text>
                    <Text style={styles.payPriceText}>¥{(this.state.orderInfo.tailPayment + this.state.orderInfo.detectionFee) / 100}</Text>
                </View>



            </View>
        )
    }

    copyText(copyText) {
        Clipboard.setString(copyText);
        ToastToUser('复制成功');
    }

    renderBottom() {
        return (
            <View style={[styles.bottomContain, { paddingBottom: Constant.bottomHeight }]}>
                {Constant.userInfo.isFranchisee == 0 && this.state.orderStatus == OrderStatus.OrderStatusWaitSign && (this.state.orderInfo.sellerCancelStatus != '1' && this.state.orderInfo.buyerCancelStatus != '1')
                && this.state.checkStatus == '3' ?
                    <View style={styles.contractFeeContain}>
                        <Text style={styles.itemPriceTitle}>合同费用<Text style={{ color: '#999999' }}>（余额扣款）</Text></Text>
                        <Text style={[styles.itemPriceValue, { color: '#ED542E' }]}>¥{this.state.orderInfo.contractFee / 100}</Text>
                    </View>
                    :
                    null
                }

                {Constant.userInfo.isFranchisee == 0 && this.state.orderStatus == OrderStatus.OrderStatusWaitPay
                    ?
                    <View>
                        <View style={[styles.contractFeeContain, { justifyContent: 'flex-end' }]}>
                            <Text style={styles.itemPriceTitle}>总计</Text>
                            <Text style={[styles.itemPriceValue, { color: '#ED542E' }]}>¥{this.state.orderInfo.tradePrice / 100}元</Text>
                        </View>
                        <View style={styles.contractFeeContain}>
                            <Text style={styles.itemPriceTitle}></Text>
                            <Text style={styles.itemPriceTitle}>
                                {this.state.orderInfo.payType == payType.payTypeFull ? '物流提车后，车款将全款预付给卖方' : '车款一次付清，将分两笔到账'}
                            </Text>
                        </View>

                    </View>

                    :
                    null
                }

                <View style={styles.bottomContain2}>
                    <View>
                        <View style={{ flexDirection: 'row', alignItems: 'center', justifyContent: 'center', marginRight: 8 }}>
                            <TouchableOpacity
                                style={styles.bottomitemBox}
                                activeOpacity={0.8}
                                onPress={() => {
                                    this.consultOnline()
                                }}
                            >
                                <Image style={styles.bottomitemImg} source={require('source/image/chat_online_icon.png')} />
                                <Text style={styles.bottomitemText}>在线咨询</Text>
                            </TouchableOpacity>

                            {/**发货确认前能取消 */}
                            {this.state.orderStatus == OrderStatus.OrderStatusWaitSign || this.state.orderStatus == OrderStatus.OrderStatusSigning || this.state.orderStatus == OrderStatus.OrderStatusWaitPay
                            || (this.state.orderStatus == OrderStatus.OrderStatusWaitDelivery && this.state.orderInfo.shippingConfirm != '1')
                            && (this.state.orderInfo.sellerCancelStatus != '1' && this.state.orderInfo.buyerCancelStatus != '1') ?
                                (this.state.orderInfo.sellerCancelStatus != '1' && this.state.orderInfo.buyerCancelStatus != '1') ?
                                    <TouchableOpacity
                                        style={styles.bottomitemBox}
                                        activeOpacity={0.8}
                                        onPress={() => {

                                            this.setState({ isShowCacelPop: true })

                                        }}
                                    >
                                        <Image style={styles.bottomitemImg} source={require('source/image/cancel_order_icon.png')} />
                                        <Text style={styles.bottomitemText}>取消订单</Text>
                                    </TouchableOpacity>
                                    : null
                                :
                                null
                            }


                        </View>
                    </View>

                    <View>
                        {this.getRightBottomBtn()}
                    </View>
                </View>
            </View>
        )
    }

    /**
     * 车辆未自检则买家显示【申请检测】按钮，提醒卖家检测，卖家显示【立即检测】按钮。
     * 已完成检测的情况下，待签署状态，买家显示【签署合同】发起，卖家无操作按钮（除取消订单和在线咨询），然后由买家发起合同
     *
     * 签署中状态，买家未签署显示【签署合同】，卖家显示【签署合同】，卖家签署完如果买家未签署则显示【查看合同】
     *
     * 待发货状态下，双方均未确认，均显示【物流确认】，己方确认完后不显示按钮
     *
     * 待预付款状态下，买家未付款，买家显示【确认预付】，卖家显示【查看物流】，如果买家已付款，卖家未确认，买家显示【查看回执】，卖家显示【确认收款】
     *
     * 待收货状态下，卖方显示【查看物流】,买方待收货(已交车)情况下，多显示一个【复检下单】，同时均显示【查看物流】
     *
     * 待结算状态下，买家未付款，卖家无操作，买家显示【确认付款】；买家已付款，卖家显示【确认收款】
     *
     */
    getRightBottomBtn() {

        if ((Constant.userInfo.isFranchisee == '1' && this.state.orderInfo.buyerCancelStatus == '1')

            || (Constant.userInfo.isFranchisee == '0' && this.state.orderInfo.sellerCancelStatus == '1')) {

            return (
                <View style={{ flexDirection: 'row' }}>
                    <TouchableOpacity
                        activeOpacity={0.8}
                        style={[styles.bottomBtnCancel, { width: 100 }]}
                        onPress={() => {

                            this.rejectCancelOrder()
                        }}
                    >
                        <Text style={styles.bottomRightItemText}>拒绝</Text>
                    </TouchableOpacity>

                    <TouchableOpacity
                        activeOpacity={0.8}
                        style={[styles.bottomBtn1, { width: 100 }]}
                        onPress={() => {
                            this.confirmCancelOrder()
                        }}
                    >
                        <LinearGradient start={{ x: 0, y: 0 }} end={{ x: 1, y: 0 }}
                                        colors={['#FFEF3A', '#FFDB1B']}
                                        style={styles.itemInnerBox}>
                            <Text style={styles.bottomRightItemText}>确认</Text>

                        </LinearGradient>
                    </TouchableOpacity>
                </View>
            )
        } else {
            if (Constant.userInfo.isFranchisee == '1' && this.state.orderInfo.sellerCancelStatus == '1') {
                return null
            }

        }



        if ((this.state.checkStatus == '' || this.state.checkStatus == '1') && this.state.orderStatus != OrderStatus.OrderStatusCanceled) {//未自检

            if (Constant.userInfo.isFranchisee == '1') {//卖家
                return (
                    <View style={{ flexDirection: 'row' }}>
                        {/* {Constant.release ? null :
                            <TouchableOpacity
                                activeOpacity={0.8}
                                style={[styles.bottomBtn1, { width: 90, marginRight: 10 }]}
                                onPress={() => {

                                    this.setState({
                                        checkStatus: '3'
                                    })
                                }}
                            >
                                <LinearGradient start={{ x: 0, y: 0 }} end={{ x: 1, y: 0 }}
                                    colors={['#FFEF3A', '#FFDB1B']}
                                    style={styles.itemInnerBox}>
                                    <Text style={styles.bottomRightItemText}>跳过检测</Text>

                                </LinearGradient>
                            </TouchableOpacity>
                        } */}


                        <TouchableOpacity
                            activeOpacity={0.8}
                            style={styles.bottomBtn1}
                            onPress={() => {

                                navigation.navigate('CarDetectionPage', {
                                    carId: this.state.orderInfo.carId, completion: () => {
                                        this.getOrderDetail()
                                    }
                                })
                            }}
                        >
                            <LinearGradient start={{ x: 0, y: 0 }} end={{ x: 1, y: 0 }}
                                            colors={['#FFEF3A', '#FFDB1B']}
                                            style={styles.itemInnerBox}>
                                <Text style={styles.bottomRightItemText}>立即检测</Text>

                            </LinearGradient>
                        </TouchableOpacity>
                    </View>

                )
            } else {
                if (this.state.orderInfo.applyDetection == '0' && this.state.orderInfo.buyerCancelStatus != '1') {//未申请检测
                    return (
                        <TouchableOpacity
                            activeOpacity={0.8}
                            style={styles.bottomBtn1}
                            onPress={() => {

                                this.applyDetection()
                            }}
                        >
                            <LinearGradient start={{ x: 0, y: 0 }} end={{ x: 1, y: 0 }}
                                            colors={['#FFEF3A', '#FFDB1B']}
                                            style={styles.itemInnerBox}>
                                <Text style={styles.bottomRightItemText}>催促检测</Text>

                            </LinearGradient>
                        </TouchableOpacity>
                    )
                }

            }


        } else if (this.state.checkStatus == '3') {//已检测

            if (this.state.orderStatus == OrderStatus.OrderStatusWaitSign || this.state.orderStatus == OrderStatus.OrderStatusRejectSign) {//待签署
                if (Constant.userInfo.isFranchisee == '1') {//卖家
                    return (
                        <TouchableOpacity
                            activeOpacity={0.8}
                            style={styles.bottomBtn1}
                            onPress={() => {
                                navigation.navigate('ModifyPricePage', {
                                    orderNo: this.state.orderNo, price: this.state.orderInfo.quotationAmount, onConfirm: (price) => {
                                        this.getOrderDetail()
                                    }
                                })

                            }}
                        >
                            <LinearGradient start={{ x: 0, y: 0 }} end={{ x: 1, y: 0 }}
                                            colors={['#FFEF3A', '#FFDB1B']}
                                            style={styles.itemInnerBox}>
                                <Text style={styles.bottomRightItemText}>修改价格</Text>

                            </LinearGradient>
                        </TouchableOpacity>
                    )
                } else {
                    return (
                        <TouchableOpacity
                            activeOpacity={0.8}
                            style={styles.bottomBtn1}
                            onPress={() => {
                                navigation.navigate('SignMainBodyPage', { orderNo: this.state.orderNo, payType: this.state.orderInfo.payType })
                            }}
                        >
                            <LinearGradient start={{ x: 0, y: 0 }} end={{ x: 1, y: 0 }}
                                            colors={['#FFEF3A', '#FFDB1B']}
                                            style={styles.itemInnerBox}>
                                <Text style={styles.bottomRightItemText}>发起合同</Text>

                            </LinearGradient>
                        </TouchableOpacity>
                    )
                }
            }

            else if (this.state.orderStatus == OrderStatus.OrderStatusSigning) {//签署中

                if (Constant.userInfo.isFranchisee == '1') {//卖家
                    if (this.state.orderInfo.sellerContractSign == '1') {//卖家已签署

                    } else {
                        return (
                            <TouchableOpacity
                                activeOpacity={0.8}
                                style={styles.bottomBtn1}
                                onPress={() => {
                                    navigation.navigate('ContractDetailPage', { contractNo: this.state.orderInfo.contractNo, orderNo: this.state.orderNo })

                                }}
                            >
                                <LinearGradient start={{ x: 0, y: 0 }} end={{ x: 1, y: 0 }}
                                                colors={['#FFEF3A', '#FFDB1B']}
                                                style={styles.itemInnerBox}>
                                    <Text style={styles.bottomRightItemText}>签署合同</Text>

                                </LinearGradient>
                            </TouchableOpacity>
                        )
                    }
                } else {
                    if (this.state.orderInfo.sellerContractSign == '1') {//买家已签署

                    } else {
                        if (this.state.orderInfo.buyerContractSign != '1') {
                            return (
                                <TouchableOpacity
                                    activeOpacity={0.8}
                                    style={styles.bottomBtn1}
                                    onPress={() => {
                                        navigation.navigate('ContractDetailPage', { contractNo: this.state.orderInfo.contractNo, orderNo: this.state.orderNo })

                                    }}
                                >
                                    <LinearGradient start={{ x: 0, y: 0 }} end={{ x: 1, y: 0 }}
                                                    colors={['#FFEF3A', '#FFDB1B']}
                                                    style={styles.itemInnerBox}>
                                        <Text style={styles.bottomRightItemText}>签署合同</Text>

                                    </LinearGradient>
                                </TouchableOpacity>
                            )
                        }

                    }
                }



            } else if (this.state.orderStatus == OrderStatus.OrderStatusWaitDelivery) {//待发货
                if (Constant.userInfo.isFranchisee == '1') {//卖家
                    if (!this.state.orderInfo.shippingConfirm || this.state.orderInfo.shippingConfirm == '0') {//卖家未确认物流
                        return (
                            <TouchableOpacity
                                activeOpacity={0.8}
                                style={styles.bottomBtn1}
                                onPress={() => {
                                    navigation.navigate('LogisticsOrderingSubmitPage', {
                                        orderNo: this.state.orderNo, submitHandler: () => {
                                            this.getOrderDetail()
                                        }
                                    })
                                }}
                            >
                                <LinearGradient start={{ x: 0, y: 0 }} end={{ x: 1, y: 0 }}
                                                colors={['#FFEF3A', '#FFDB1B']}
                                                style={styles.itemInnerBox}>
                                    <Text style={styles.bottomRightItemText}>物流确认</Text>

                                </LinearGradient>
                            </TouchableOpacity>
                        )
                    }
                } else {
                    if (!this.state.orderInfo.deliveryConfirm || this.state.orderInfo.deliveryConfirm == '0') {//买家未确认物流
                        return (
                            <TouchableOpacity
                                activeOpacity={0.8}
                                style={styles.bottomBtn1}
                                onPress={() => {
                                    navigation.navigate('LogisticsOrderingSubmitPage', {
                                        orderNo: this.state.orderNo, submitHandler: () => {
                                            this.getOrderDetail()
                                        }
                                    })
                                }}
                            >
                                <LinearGradient start={{ x: 0, y: 0 }} end={{ x: 1, y: 0 }}
                                                colors={['#FFEF3A', '#FFDB1B']}
                                                style={styles.itemInnerBox}>
                                    <Text style={styles.bottomRightItemText}>物流确认</Text>

                                </LinearGradient>
                            </TouchableOpacity>
                        )
                    }
                }
            } else if (this.state.orderStatus == OrderStatus.OrderStatusWaitPay) {//付款
                //待预付款状态下，买家未付款，买家显示【确认预付】，卖家显示【查看物流】，如果买家已付款，卖家未确认，买家显示【查看回执】，卖家显示【确认收款】
                if (Constant.userInfo.isFranchisee == '1') {//卖家
                    if (this.state.orderInfo.advancePaymentStatus == '0') {//买家未付款

                    } else {

                    }
                } else {
                    if (this.state.orderInfo.advancePaymentStatus == '0') {//买家未付款
                        return (
                            <TouchableOpacity
                                activeOpacity={0.8}
                                style={styles.bottomBtn1}
                                onPress={() => {
                                    this.confirmPay(this.state.orderInfo.tradePrice)
                                }}
                            >
                                <LinearGradient start={{ x: 0, y: 0 }} end={{ x: 1, y: 0 }}
                                                colors={['#FFEF3A', '#FFDB1B']}
                                                style={styles.itemInnerBox}>
                                    <Text style={styles.bottomRightItemText}>确认支付</Text>

                                </LinearGradient>
                            </TouchableOpacity>
                        )
                    } else {
                        // return (
                        //     <TouchableOpacity
                        //         activeOpacity={0.8}
                        //         style={styles.bottomBtn1}
                        //         onPress={() => {
                        //             navigation.navigate('ConfirmReceivePayPage', { orderNo: this.state.orderNo, from: '1', confirmReceivePay: false })
                        //         }}
                        //     >
                        //         <LinearGradient start={{ x: 0, y: 0 }} end={{ x: 1, y: 0 }}
                        //             colors={['#FFEF3A', '#FFDB1B']}
                        //             style={styles.itemInnerBox}>
                        //             <Text style={styles.bottomRightItemText}>查看回执</Text>

                        //         </LinearGradient>
                        //     </TouchableOpacity>
                        // )
                    }
                }
            }
            else if (this.state.orderStatus == OrderStatus.OrderStatusWaitReceipt) {//待收货
                //待收货状态下，卖方显示【查看物流】,买方待收货(已交车)情况下，多显示一个【复检下单】，同时均显示【查看物流】
                if (Constant.userInfo.isFranchisee == '1') {//卖家

                } else {

                    if (!this.state.orderInfo.repetitionDetectionStatus || this.state.orderInfo.repetitionDetectionStatus == '') {
                        return (
                            <View style={{ flexDirection: 'row' }}>

                                {this.state.orderInfo.logisticsStatus == '30' || this.state.orderInfo.isSelfPickup == '1' ?
                                    <TouchableOpacity
                                        activeOpacity={0.8}
                                        style={styles.bottomBtn1}
                                        onPress={() => {
                                            navigation.navigate('CarDetectionPage', { carId: this.state.orderInfo.carId, type: '1' })
                                        }}
                                    >
                                        <LinearGradient start={{ x: 0, y: 0 }} end={{ x: 1, y: 0 }}
                                                        colors={['#FFEF3A', '#FFDB1B']}
                                                        style={styles.itemInnerBox}>
                                            <Text style={styles.bottomRightItemText}>复检下单</Text>

                                        </LinearGradient>
                                    </TouchableOpacity>
                                    :
                                    null
                                }



                            </View>
                        )
                    } else {

                    }

                }

            }
            else if (this.state.orderStatus == OrderStatus.OrderStatusWaitSettlement) {//待结算
                //待结算状态下，买家未付款，卖家无操作，买家显示【确认付款】；买家已付款，卖家显示【确认收款】
                if (Constant.userInfo.isFranchisee == '1') {//卖家


                } else {
                    return (
                        <View style={{ flexDirection: 'row' }}>
                            {/* 判断是全选预付就隐藏售后 */}
                            {this.state.orderInfo.payType == payType.payTypeFull ? null :
                                <TouchableOpacity
                                    activeOpacity={0.8}
                                    style={[styles.bottomBtn1, { marginRight: 10 }]}
                                    onPress={() => {
                                        navigation.navigate('ApplySaleServicePage', { orderNo: this.state.orderNo })

                                    }}
                                >
                                    <LinearGradient start={{ x: 0, y: 0 }} end={{ x: 1, y: 0 }}
                                                    colors={['#FFEF3A', '#FFDB1B']}
                                                    style={styles.itemInnerBox}>
                                        <Text style={styles.bottomRightItemText}>申请售后</Text>

                                    </LinearGradient>
                                </TouchableOpacity>
                            }
                            <TouchableOpacity
                                activeOpacity={0.8}
                                style={styles.bottomBtn1}
                                onPress={() => {
                                    navigation.navigate('ConfirmReceiveCar', { carId: this.state.orderInfo.carId, from: '1', orderNo: this.state.orderNo })
                                }}
                            >
                                <LinearGradient start={{ x: 0, y: 0 }} end={{ x: 1, y: 0 }}
                                                colors={['#FFEF3A', '#FFDB1B']}
                                                style={styles.itemInnerBox}>
                                    <Text style={styles.bottomRightItemText}>确认收货</Text>

                                </LinearGradient>
                            </TouchableOpacity>
                        </View>

                    )
                }
            }
            else if (this.state.orderStatus == OrderStatus.OrderStatusServicing) {//售后中
                if (Constant.userInfo.isFranchisee == '1') {//卖家
                    return (
                        <TouchableOpacity
                            activeOpacity={0.8}
                            style={styles.bottomBtn1}
                            onPress={() => {
                                navigation.navigate('AfterSaleOrderDetail', { orderNo: this.state.afterSalesNo })

                            }}
                        >
                            <LinearGradient start={{ x: 0, y: 0 }} end={{ x: 1, y: 0 }}
                                            colors={['#FFEF3A', '#FFDB1B']}
                                            style={styles.itemInnerBox}>
                                <Text style={styles.bottomRightItemText}>处理售后</Text>

                            </LinearGradient>
                        </TouchableOpacity>
                    )
                } else {
                    return (
                        <TouchableOpacity
                            activeOpacity={0.8}
                            style={styles.bottomBtn1}
                            onPress={() => {
                                navigation.navigate('AfterSaleOrderDetail', { orderNo: this.state.afterSalesNo })

                            }}
                        >
                            <LinearGradient start={{ x: 0, y: 0 }} end={{ x: 1, y: 0 }}
                                            colors={['#FFEF3A', '#FFDB1B']}
                                            style={styles.itemInnerBox}>
                                <Text style={styles.bottomRightItemText}>处理售后</Text>

                            </LinearGradient>
                        </TouchableOpacity>
                    )
                }
            }
            else if (this.state.orderStatus == OrderStatus.OrderStatusCanceled) {//已取消


            }
            else if (this.state.orderStatus == OrderStatus.OrderStatusFinisded) {//已完成
                if (Constant.userInfo.isFranchisee == '1') {//卖家
                    return (
                        <View style={{ flexDirection: 'row', alignItems: 'center' }}>

                            {this.state.transferDocumentUploaded == '1' ?

                                <TouchableOpacity
                                    activeOpacity={0.8}
                                    style={styles.bottomBtn1}
                                    onPress={() => {
                                        navigation.navigate('ConfirmReceiveCar', { from: '2', orderNo: this.state.orderNo })

                                    }}
                                >
                                    <LinearGradient start={{ x: 0, y: 0 }} end={{ x: 1, y: 0 }}
                                                    colors={['#FFEF3A', '#FFDB1B']}
                                                    style={styles.itemInnerBox}>
                                        <Text style={styles.bottomRightItemText}>过户资料</Text>

                                    </LinearGradient>
                                </TouchableOpacity>

                                : null
                            }




                            {this.state.afterSalesNo && this.state.afterSalesNo != '' ?
                                <TouchableOpacity
                                    activeOpacity={0.8}
                                    style={[styles.bottomBtn1, { marginLeft: 10 }]}
                                    onPress={() => {
                                        navigation.navigate('AfterSaleOrderDetail', { orderNo: this.state.afterSalesNo })

                                    }}
                                >
                                    <LinearGradient start={{ x: 0, y: 0 }} end={{ x: 1, y: 0 }}
                                                    colors={['#FFEF3A', '#FFDB1B']}
                                                    style={styles.itemInnerBox}>
                                        <Text style={styles.bottomRightItemText}>查看售后</Text>

                                    </LinearGradient>
                                </TouchableOpacity>
                                : null
                            }

                        </View>

                    )
                } else {
                    return (
                        <View style={{ flexDirection: 'row', alignItems: 'center' }}>

                            <TouchableOpacity
                                activeOpacity={0.8}
                                style={[styles.bottomBtn1, { marginRight: 10 }]}
                                onPress={() => {
                                    if (this.state.transferDocumentUploaded == '1') {
                                        navigation.navigate('ConfirmReceiveCar', { orderNo: this.state.orderNo, from: '2' })
                                    } else {
                                        navigation.navigate('ConfirmReceiveCar', { orderNo: this.state.orderNo, from: '3' })
                                    }


                                }}
                            >
                                <LinearGradient start={{ x: 0, y: 0 }} end={{ x: 1, y: 0 }}
                                                colors={['#FFEF3A', '#FFDB1B']}
                                                style={styles.itemInnerBox}>
                                    <Text style={styles.bottomRightItemText}>{this.state.transferDocumentUploaded == '1' ? '过户资料' : '上传资料'}</Text>

                                </LinearGradient>
                            </TouchableOpacity>



                            {this.state.afterSalesNo && this.state.afterSalesNo != '' ?
                                <TouchableOpacity
                                    activeOpacity={0.8}
                                    style={styles.bottomBtn1}
                                    onPress={() => {
                                        navigation.navigate('AfterSaleOrderDetail', { orderNo: this.state.afterSalesNo })

                                    }}
                                >
                                    <LinearGradient start={{ x: 0, y: 0 }} end={{ x: 1, y: 0 }}
                                                    colors={['#FFEF3A', '#FFDB1B']}
                                                    style={styles.itemInnerBox}>
                                        <Text style={styles.bottomRightItemText}>查看售后</Text>

                                    </LinearGradient>
                                </TouchableOpacity>
                                : null
                            }
                        </View>
                    )
                }
            }

            else if (this.state.orderStatus == OrderStatus.OrderStatusClosed) {//已关闭
                return (
                    <View style={{ flexDirection: 'row', alignItems: 'center' }}>


                        {this.state.afterSalesNo && this.state.afterSalesNo != '' ?
                            <TouchableOpacity
                                activeOpacity={0.8}
                                style={[styles.bottomBtn1, { marginLeft: 10 }]}
                                onPress={() => {
                                    navigation.navigate('AfterSaleOrderDetail', { orderNo: this.state.afterSalesNo })

                                }}
                            >
                                <LinearGradient start={{ x: 0, y: 0 }} end={{ x: 1, y: 0 }}
                                                colors={['#FFEF3A', '#FFDB1B']}
                                                style={styles.itemInnerBox}>
                                    <Text style={styles.bottomRightItemText}>查看售后</Text>

                                </LinearGradient>
                            </TouchableOpacity>
                            : null
                        }

                    </View>

                )
            }
            else {


                return (
                    <View>

                    </View>
                )
            }
        }


    }

    /**
     * 申请检测
     */
    applyDetection() {

        if (this.Loading) {
            this.Loading.show('申请检测中...')
        }

        let param = {
            orderNo: this.state.orderNo,
        }

        HttpUtils.getRequest(HttpUrls.orderApplyDetection, param)
            .then((result) => {
                if (this.Loading) {
                    this.Loading.hide()
                }
                if (result.code == 0) {
                    setTimeout(() => {

                        navigation.navigate('MessageChat', {
                            imGroupId: result.data.imConversationId ? result.data.imConversationId : '',
                            carId: this.state.orderInfo.carId
                        })
                        this.getOrderDetail()
                    }, 500)

                } else {
                    ToastToUser(result.msg ? result.msg : result.statusText)
                }
            })
            .catch((error) => {
                if (this.Loading) {
                    this.Loading.hide()
                }
            });


    }

    getOrderDetail() {
        let that = this
        let param = {
            orderNo: this.state.orderNo
        }

        HttpUtils.getRequest(HttpUrls.getDetailsByOrderNo, param)
            .then((result) => {
                if (this.Loading) {
                    this.Loading.hide();
                }
                if (result.code == 0 && result.data) {

                    console.log('result.data==', result.data.payType)

                    this.setState({
                        orderInfo: result.data,
                        orderStatus: result.data.orderStatus,
                        title: conditionObjWithType('orderStatus')[result.data.orderStatus],
                        receivePaymentBank: result.data.sellerReceiveBankName,
                        receivePaymentBankAccount: result.data.sellerReceiveBankAccount,
                        receivePaymentAccountName: result.data.sellerReceiveAccountName,
                        checkStatus: result.data.detectionStatus ? result.data.detectionStatus : '',
                        certificateInfoRO: result.data.certificateInfoRO,
                        transferDocumentUploaded: result.data.transferDocumentUploaded
                    })

                    // tsk 如果是全款支付订单，跳过检测流程，以适应原来流程的UI
                    if(result.data?.payType == payType.payTypeFull){
                        this.setState({
                            checkStatus: 3
                        })
                    }

                    console.log('this.state.certificateInfoRO', result.data.certificateInfoRO)

                    if (result.data.logisticsNo && result.data.logisticsNo != '') {
                        this.getByLogisticsNo(result.data.logisticsNo)
                    }

                    if ((result.data.orderStatus == OrderStatus.OrderStatusWaitSign || result.data.orderStatus == OrderStatus.OrderStatusSigning)) {
                        if (result.data.contractSignTimeOut) {
                            let endDate = result.data.contractSignTimeOut

                            const timer = setInterval(() => {
                                endDate = endDate - 1;
                                if (endDate <= 0) {
                                    clearInterval(timer);

                                }
                                that.setState({
                                    contractSignTimeOut: endDate
                                })
                            }, 1000);
                        } else {
                            that.setState({
                                contractSignTimeOut: 0
                            })
                        }


                    }

                    if (result.data.orderStatus == OrderStatus.OrderStatusWaitDelivery) {

                        if (result.data.shipmentTimeOut) {
                            let endDate = result.data.shipmentTimeOut

                            const timer = setInterval(() => {
                                endDate = endDate - 1;
                                if (endDate <= 0) {
                                    clearInterval(timer);

                                }
                                that.setState({
                                    shipmentTimeOut: endDate
                                })
                            }, 1000);
                        } else {
                            that.setState({
                                shipmentTimeOut: 0
                            })
                        }
                        // if (result.data.receiptTimeOut) {
                        //     let endDate = result.data.receiptTimeOut

                        //     const timer = setInterval(() => {
                        //         endDate = endDate - 1;
                        //         if (endDate <= 0) {
                        //             clearInterval(timer);

                        //         }
                        //         that.setState({
                        //             receiptTimeOut: endDate
                        //         })
                        //     }, 1000);
                        // }


                    }

                    if (result.data.orderStatus == OrderStatus.OrderStatusServicing || result.data.orderStatus == OrderStatus.OrderStatusFinisded ||
                        result.data.orderStatus == OrderStatus.OrderStatusClosed) {
                        this.getAfterSalesLastByOrderNo()
                    }

                    if (result.data.orderStatus == OrderStatus.OrderStatusWaitPay) {

                        if (result.data.payTimeOut) {
                            let endDate = result.data.payTimeOut

                            const timer = setInterval(() => {
                                endDate = endDate - 1;
                                if (endDate <= 0) {
                                    clearInterval(timer);

                                }
                                that.setState({
                                    payTimeOut: endDate
                                })
                            }, 1000);
                        } else {
                            that.setState({
                                payTimeOut: 0
                            })
                        }


                    }

                    if (result.data.orderStatus == OrderStatus.OrderStatusWaitReceipt) {
                        //logisticsTimeOut
                        if (result.data.logisticsTimeOut) {
                            let endDate = result.data.logisticsTimeOut

                            const timer = setInterval(() => {
                                endDate = endDate - 1;
                                if (endDate <= 0) {
                                    clearInterval(timer);

                                }
                                that.setState({
                                    logisticsTimeOut: endDate
                                })
                            }, 1000);
                        } else {
                            that.setState({
                                logisticsTimeOut: 0
                            })
                        }

                    }

                    //repetitionDetectionTimeOut
                    if (result.data.orderStatus == OrderStatus.OrderStatusWaitReceipt) {
                        //logisticsTimeOut
                        if (result.data.repetitionDetectionTimeOut) {
                            let endDate = result.data.repetitionDetectionTimeOut

                            const timer = setInterval(() => {
                                endDate = endDate - 1;
                                if (endDate <= 0) {
                                    clearInterval(timer);

                                }
                                that.setState({
                                    repetitionDetectionTimeOut: endDate
                                })
                            }, 1000);
                        } else {
                            that.setState({
                                repetitionDetectionTimeOut: 0
                            })
                        }

                    }

                    if (result.data.orderStatus == OrderStatus.OrderStatusWaitSettlement) {

                        if (result.data.settlinTimeOut) {
                            let endDate = result.data.settlinTimeOut
                            const timer = setInterval(() => {
                                endDate = endDate - 1;
                                if (endDate <= 0) {
                                    clearInterval(timer);
                                }
                                that.setState({
                                    settlinTimeOut: endDate
                                })
                            }, 1000);
                        } else {
                            that.setState({
                                settlinTimeOut: 0
                            })
                        }

                    }
                }

            })
            .catch((error) => {
                if (this.Loading) {
                    this.Loading.hide();
                }
            });
    }

    getAfterSalesLastByOrderNo() {
        HttpUtils.getRequest(HttpUrls.getAfterSalesLastByOrderNo, { quotationOrderNo: this.state.orderNo })
            .then((result) => {
                if (result.code == 0 && result.data) {
                    this.setState({
                        afterSalesNo: result.data.afterSalesNo,
                        buyerAfterSalesStatus: result.data.buyerCancelStatus
                    })
                }
            })
            .catch((error) => {

            });
    }

    // 物流自提
    ziTi() {

        let param = {
            orderNo: this.state.orderNo
        }
        if (this.Loading) {
            this.Loading.show('请稍等...')
        }
        HttpUtils.getRequest(HttpUrls.buyerSubmitSelfPickup, param)
            .then((result) => {
                if (this.Loading) {
                    this.Loading.hide();
                }
                if (result.code == 0) {
                    // ToastToUser('自提')
                    setTimeout(() => {
                        navigation.navigate('MessageChat', { imGroupId: this.state.orderInfo.imConversationId, carId: this.state.orderInfo.carId })
                    }, 500)
                    this.getOrderDetail()
                }else{
                    ToastToUser(result.msg ? result.msg : result.statusText)
                }
            })
            .catch((error) => {
                if (this.Loading) {
                    this.Loading.hide();
                }
            })

    }

    // 查询支付状态
    checkPayStatus(){
        let param = {
            paymentId: this.state.paymentId
        }

        if (this.Loading) {
            this.Loading.show('查询中...')
        }

        HttpUtils.getRequest(HttpUrls.checkPaymentResult, param)
            .then((result) => {
                console.log('checkPayStatus====', result)
                if (this.Loading) {
                    this.Loading.hide()
                }
                if (result.code == 0) {
                    if(result.data?.status == '102'){
                        setTimeout(() => {
                            this.getOrderDetail()
                        }, 200)
                        ToastToUser('订单支付成功')
                    }else {
                        ToastToUser('如已支付,请稍后查看支付结果')
                    }
                }else{
                    ToastToUser(result.msg ? result.msg : result.statusText)
                }
            })
            .catch((error) => {
                if (this.Loading) {
                    this.Loading.hide()
                }
            })
    }

    /**
     * 获取物流详情
     */
    getByLogisticsNo(logisticsNo) {
        HttpUtils.getRequest(HttpUrls.getByLogisticsNo, { logisticsNo: logisticsNo })
            .then((result) => {
                if (result.code == 0) {
                    let data = result.data;
                    this.setState({
                        logisticsInfo: data
                    })
                } else {
                    ToastToUser(result.msg ? result.msg : result.statusText)
                }
            })
            .catch((error) => {
                // ToastToUser(error)
            });
    }


    cancelOrder(reason) {
        let param = {
            orderNo: this.state.orderNo,
            reason: reason
        }

        let url = ''
        if (Constant.userInfo.isFranchisee == 1) {//卖家
            url = HttpUrls.sellerCancelOrder
        } else {
            url = HttpUrls.buyerCancelOrder
        }

        HttpUtils.getRequest(url, param)
            .then((result) => {
                if (result.code == 0) {
                    ToastToUser('取消订单申请提交成功')
                    // this.props.navigation.goBack()
                    setTimeout(() => {
                        navigation.navigate('MessageChat', { imGroupId: this.state.orderInfo.imConversationId, carId: this.state.orderInfo.carId })
                    }, 500)

                    this.getOrderDetail()
                }else{
                    ToastToUser(result.msg ? result.msg : result.statusText)
                }
            })
            .catch((error) => {

            })

    }

    consultOnline() {
        let param = {
            carId: this.state.orderInfo.carId,
            buyerMerchantId: this.state.orderInfo.buyerMerchantId,
            sellerMerchantId: this.state.orderInfo.sellerMerchantId,
            buyerUserId: this.state.orderInfo.buyerUserId,
        }
        if (this.Loading) {
            this.Loading.show();
        }

        HttpUtils.postRequest(HttpUrls.quotationConsult, param)
            .then((result) => {
                if (this.Loading) {
                    this.Loading.hide();
                }
                if (result.code == 0) {

                    setTimeout(() => {
                        navigation.navigate('MessageChat', {
                            imGroupId: result.data.imGroupId,
                            carId: this.state.orderInfo.carId
                        })
                    }, 500);

                } else {
                    ToastToUser(result.msg + '')
                }
            })
            .catch((error) => {
                if (this.Loading) {
                    this.Loading.hide();
                }
            });
    }



    /**
     * 拒绝取消订单
     */
    rejectCancelOrder() {
        if (this.Loading) {
            this.Loading.show('提交中...')
        }
        let params = {
            orderNo: this.state.orderNo,
            operationType: 3
        }

        let url = ''
        if (Constant.userInfo.isFranchisee == 1) {//卖家
            url = HttpUrls.sellerHandleCancel
        } else {
            url = HttpUrls.buyerHandleCancel
        }

        HttpUtils.getRequest(url, params)
            .then((result) => {
                if (this.Loading) {
                    this.Loading.hide()
                }
                if (result.code == 0) {
                    ToastToUser('拒绝取消订单成功')
                    this.getOrderDetail()
                }else{
                    ToastToUser(result.msg ? result.msg : result.statusText)
                }
            })
            .catch((error) => {
                if (this.Loading) {
                    this.Loading.hide()
                }
            })
    }

    /**
     * 同意取消订单
     */
    confirmCancelOrder() {
        if (this.Loading) {
            this.Loading.show('提交中...')
        }
        let params = {
            orderNo: this.state.orderNo,
            operationType: 2
        }

        let url = ''
        if (Constant.userInfo.isFranchisee == 1) {//卖家
            url = HttpUrls.sellerHandleCancel
        } else {
            url = HttpUrls.buyerHandleCancel
        }

        HttpUtils.getRequest(url, params)
            .then((result) => {
                if (this.Loading) {
                    this.Loading.hide()
                }
                if (result.code == 0) {
                    ToastToUser('同意取消订单成功')
                    this.getOrderDetail()

                    setTimeout(() => {
                        navigation.navigate('MessageChat', { imGroupId: this.state.orderInfo.imConversationId, carId: this.state.orderInfo.carId })
                    }, 500)
                }else{
                    ToastToUser(result.msg ? result.msg : result.statusText)
                }
            })
            .catch((error) => {
                if (this.Loading) {
                    this.Loading.hide()
                }
            })
    }

    /**
     * 买家支付车款
     * @param {*} totalAmount
     */
    confirmPay(totalAmount) {
        let param = {
            userId: Constant.userInfo.userId,
            merchantId: Constant.userInfo.merchantId,
            totalAmount: totalAmount,
            payChannel: 10,
            tradeType: 22,
            operator: Constant.userInfo.fullname,
            outTradeNo: this.state.orderNo
        }

        if (this.Loading) {
            this.Loading.show()
        }
        HttpUtils.postRequest(HttpUrls.paymentOrderGenerate, param)
            .then((result) => {
                if (this.Loading) {
                    this.Loading.hide();
                }
                let code = result.code
                if (code == 0) {
                    let data = result.data
                    let channelResult = data.channelResult
                    console.log('paymentOrderGenerate==', result)
                    if (channelResult) {
                        this.props.navigation.navigate('WebView', { source: channelResult })
                        setTimeout( () => {
                            this.setState({
                                showAlertData: {
                                    title: '您是否已经付款?',
                                    cancelBtnText: '未支付',
                                    sureBtnText: '我已付款',
                                    type: 'payConfirm'
                                },
                                showAlertCommonView: true,
                                paymentId: data.id
                            })
                        }, 1000)

                    }
                } else {
                    ToastToUser(result.msg + '')
                }
            })
            .catch((error) => {
                if (this.Loading) {
                    this.Loading.hide();
                }
            });
    }


    /**
     * 上传检测报告
     */
    orderUploadDetectionReport() {
        let param = {
            carId: this.state.orderInfo.carId,
            vcode: this.state.orderInfo.vcode,

            operator: Constant.userInfo.fullname,
            merchantId: Constant.userInfo.merchantId,
            userId: Constant.userInfo.userId
        }


        if (this.state.detectionReportPic != '') {
            param.reportPics = this.state.detectionReportPic
        }
        if (this.state.detectionReportPdf != '') {
            param.reportPdf = this.state.detectionReportPdf
        }
        if (this.state.detectionReportUrl != '') {
            param.reportUrl = this.state.detectionReportUrl
        }

        if (this.Loading) {
            this.Loading.show()
        }
        HttpUtils.postRequest(HttpUrls.orderUploadDetectionReport, param)
            .then((result) => {
                if (this.Loading) {
                    this.Loading.hide();
                }
                let code = result.code
                if (code == 0) {
                    ToastToUser('检测报告上传成功')
                    setTimeout(() => {
                        this.getOrderDetail()
                    }, 500)

                } else {
                    ToastToUser(result.msg + '')
                }
            })
            .catch((error) => {
                if (this.Loading) {
                    this.Loading.hide();
                }
            });
    }


}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: '#F9F9F9',
    },
    scrollContain: {
        flex: 1
    },
    orderStatusContain: {
        marginTop: 15,
        marginLeft: 15,
        marginRight: 15,
        paddingLeft: 9,
    },
    orderStatusText: {
        fontSize: 18,
        fontWeight: 'bold',
        color: '#000000'
    },
    orderStatusText2: {
        fontSize: 12,
        color: '#666666',
        marginTop: 4
    },
    timeColorText: {
        fontSize: 12,
        color: '#ED542E'
    },
    addressInfoBox: {
        flexDirection: 'row',
        alignItems: 'center',
        marginLeft: 8,
        marginRight: 8,
        padding: 16,
        backgroundColor: '#fff',
        borderRadius: 6,
        marginTop: 10
    },
    locationImg: {
        width: 24,
        height: 24
    },
    addressText: {
        lineHeight: 21,
        fontSize: 15,
        fontWeight: '500',
        color: '#222'
    },
    nameText: {
        marginTop: 6,
        fontSize: 14,
        color: '#666666'
    },
    arrowImg: {
        width: 15,
        height: 15,
        marginLeft: 12,
    },
    orderInfoContain: {
        marginTop: 10,
        marginLeft: 8,
        marginRight: 8,

        backgroundColor: '#fff',
        borderRadius: 6,
        paddingHorizontal: 16,
        paddingVertical: 12,
    },
    carImg: {
        width: 130,
        height: 90,
        borderRadius: 4,
        backgroundColor: '#f5f5f5'
    },
    carInfoBox: {
        flex: 1,
        flexDirection: 'column',

        justifyContent: 'space-between',
        marginLeft: 12,
        height: 90,

    },
    brandText: {
        // lineHeight: 20,
        color: '#333333',
        fontSize: 14,
        fontWeight: '500'
    },
    carInfoText: {
        marginTop: 4,
        fontSize: 12,
        color: '#333'
    },
    carPriceText: {
        marginTop: 8,
        fontSize: 14,
        color: '#333333'
    },

    itemPriceContain: {
        flexDirection: 'row',
        alignItems: 'center',
        justifyContent: 'space-between',
        height: 46
    },
    itemPriceTitle: {
        fontSize: 14,
        color: '#333333'
    },
    itemPriceValue: {
        fontSize: 14,
        color: '#333333',
        fontWeight: 'bold'
    },
    titleText: {
        fontSize: 16,
        color: '#333333',
        fontWeight: 'bold',
        marginBottom: 10
    },
    infoBox: {
        height: 46,
        flexDirection: 'row',
        alignItems: 'center',
        justifyContent: 'space-between',
    },
    itemTitleText: {
        color: '#333',
        fontSize: 14,
    },
    itemPriceText: {
        fontSize: 14,
        fontWeight: '500',
        color: '#333'
    },
    lookBankInfoContain: {
        height: 50,
        justifyContent: 'center',
        alignItems: 'center'
    },
    lookBtnText: {
        fontSize: 14,
        color: '#FF7B00'
    },

    payPriceText: {
        fontSize: 14,
        color: '#ED542E',
        fontWeight: 'bold'
    },

    bottomContain: {
        // height: 60,
        backgroundColor: '#fff',
        borderTopColor: '#e4e4e4',
        borderTopWidth: 0.3,
        paddingTop: 5
    },
    bottomContain2: {
        height: 50,
        flexDirection: 'row',
        alignItems: 'center',
        justifyContent: 'space-between',
        paddingHorizontal: 16

    },
    bottomitemBox: {
        height: '100%',
        width: 45,
        marginRight: 5,
        flexDirection: 'column',
        justifyContent: 'center',
        alignItems: 'center',
    },
    bottomitemImg: {
        width: 18,
        height: 18
    },
    bottomitemText: {
        color: '#333333',
        fontSize: 10,
        marginTop: 4,
    },
    bottomBtn1: {
        width: 120,
        height: 36,
        justifyContent: 'center',
        alignItems: 'center',

        borderRadius: 36
    },
    bottomBtnCancel: {
        width: 120,
        height: 36,
        justifyContent: 'center',
        alignItems: 'center',

        borderRadius: 36,
        borderColor: '#E5E5E5',
        borderWidth: 1,
        marginRight: 12
    },
    itemInnerBox: {
        width: '100%',
        height: '100%',
        justifyContent: 'center',
        alignItems: 'center',
        borderRadius: 18,

    },
    bottomRightItemText: {
        color: '#333333',
        fontSize: 14
    },
    contractFeeContain: {
        height: 42,
        flexDirection: 'row',
        alignItems: 'center',
        justifyContent: 'space-between',
        paddingHorizontal: 16
    },

    carbottomContain: {
        height: 48,
        flexDirection: 'row',
        alignItems: 'center',
        justifyContent: 'flex-end',

    },
    carBottomBtn: {
        width: 88,
        height: 32,
        justifyContent: 'center',
        alignItems: 'center',
        borderRadius: 36,
        borderColor: '#E5E5E5',
        borderWidth: 1,
        marginLeft: 10
    },
    carBottomBtnText: {
        color: '#333333',
        fontSize: 14
    },

    copyImg: {
        width: 20,
        height: 20
    },
    rightBox: {
        height: '100%',
        width: 70,
        flexDirection: 'row',
        alignItems: 'center',
        justifyContent: 'flex-end',
    },
    rightText: {
        fontSize: 14,
        color: '#333333',

    },

})